package guiCode;

import java.sql.SQLException;

import com.sun.rowset.CachedRowSetImpl;

import basic.ClientConsole;
import flexibility.serverIP;
import flexibility.userData;

public class blockAccessCode {
	
	
	
	private userData userInfo = new userData();
	private ClientConsole startConnection;
	private CachedRowSetImpl crs;
	
	
	public blockAccessCode(ClientConsole conn){
		super();
		
	try {
		crs = new CachedRowSetImpl();
	} catch (SQLException e) {
		
		e.printStackTrace();
	}
	setConnection(conn);
	
	}
	
	
	public String[] getStudent(){
		String s[]=new String[1000] ;
		int i;
		s[0]="Select...";
		userInfo.deleteAll();// reset user info
		userInfo.addData(62);
		userInfo.addData(1);
		startConnection.acceptMsg(userInfo);
		crs=startConnection.getResults();
		for(i=1;i<=crs.size();i++){
			try {
				crs.next();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			try {
				s[i]=crs.getString("studentID").concat(" ,"+crs.getString("studentLastName")).concat(" "+crs.getString("studentFirstName"));
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		
		}
		
		return s;
	}
	
	public CachedRowSetImpl getParentDetails(String studentID) {
		userInfo.deleteAll();// reset user info
		userInfo.addData(63);
		userInfo.addData(1);
		userInfo.addData(studentID);
		startConnection.acceptMsg(userInfo);
		crs=startConnection.getResults();
		return crs;
		
	}
	void setConnection(ClientConsole conn){
		this.startConnection=conn;
		
	}


	public void setBlockStatus(boolean isBlocked, Object parentID) {
		userInfo.deleteAll();// reset user info
		userInfo.addData(64);
		userInfo.addData(0);
		if(isBlocked){
			
			userInfo.addData(1);
			
		}
		else
		{
			userInfo.addData(0);
			
			System.out.print("parent was unblocked"+"\n");
		}
		userInfo.addData(parentID);
		startConnection.acceptMsg(userInfo);
		
		
	}


	public String getStudentID(String s) {
		return s.substring(0, s.indexOf(" ")) ;//getout the Student ID from the given String 
		
	}


	
}
